package com.xxxy.jsq.action.distrib;

import com.xxxy.jsq.dao.DistribDao;
import com.xxxy.jsq.model.Distrib;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/updateDistribServlet")
public class UpdateDistribServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        Distrib model = new Distrib();
        DistribDao dao = new DistribDao();

        String distribFlag = request.getParameter("distrib_flag");
        String roleId = request.getParameter("role_id");
        String worksId = request.getParameter("works_id");
        String distribMemo = request.getParameter("distrib_memo");
        Long distribId = Long.valueOf(request.getParameter("distrib_id"));

        if(distribFlag != null && !distribFlag.equals("")) {
            model.setDistribFlag(distribFlag);
        }
        if(roleId != null && !roleId.equals("")) {
            model.setRoleId(roleId);
        }
        if(worksId != null && !worksId.equals("")) {
            model.setWorksId(worksId);
        }
        if(distribMemo != null && !distribMemo.equals("")) {
            model.setDistribMemo(distribMemo);
        }

        model.setDistribId(distribId);
        String str = dao.update(model);

        PrintWriter out = response.getWriter();
        out.print(str);
        out.flush();
        out.close();
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}